package com.googlecode.jmxlogger;

import java.io.File;

import com.googlecode.jmxlogger.model.JmxProcess;
import com.googlecode.jmxlogger.model.Query;
import com.googlecode.jmxlogger.model.Server;
import com.googlecode.jmxlogger.model.output.RRDWriter;
import com.googlecode.jmxlogger.model.output.StdOutWriter;
import com.googlecode.jmxlogger.util.JmxUtils;

public class Tester {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        Server server = new Server("w2", "1099");
        Query q = new Query();
        q.setObj("java.lang:type=Memory");
        q.addAttr("HeapMemoryUsage");
        q.addAttr("NonHeapMemoryUsage");
//        q.addKey("committed");
        q.addOutputWriter(new StdOutWriter());
        server.addQuery(q);

        Query q2 = new Query("java.lang:name=CMS Old Gen,type=MemoryPool");
        q2.addAttr("Usage");
        q2.addKey("committed");
        q2.addOutputWriter(new StdOutWriter());
        server.addQuery(q2);

        Query q3 = new Query();
        q3.setObj("java.lang:name=ConcurrentMarkSweep,type=GarbageCollector");
        q3.addAttr("LastGcInfo");
//        q.addKey("startTime");
//        q.addKey("memoryUsageAfterGc");
//        q.addKey("max");
        RRDWriter writer = new RRDWriter();
        writer.setOutputFile(new File("foo"));
        q3.addOutputWriter(writer);
        server.addQuery(q3);

        JmxProcess jmx = new JmxProcess(server);
        JmxUtils.prettyPrint(jmx);
        JmxUtils.execute(jmx);
    }

}
